<?php
	function oh_name_parse($s) {		
		$a = explode(":",$s);

		$name = array();
		$name['string'] 	= $s;
		$name['source'] 	= trim($a[0]);
		$name['payload'] 	= implode(":",array_slice($a,1));
		
		return $name;
	}


	function oh_name_sanitize($textname) {
		$name = $textname;
		$name = trim(strtolower($name));
		$name = str_replace(" ","-",$name);
		return $name;
	}
	
	function oh_is_name($textname) {
		if (preg_match("/^[a-zA-Z-0-9]+$/i",$textname)) {
			return true;
		} else {
			return false;	
		}
	}
	
	function oh_module_interface_file($modulename, $pack="") {
		global $oh;
		
		if ($pack) {
			return $oh['path'].'/modules/'.$pack.'/'.$modulename.'/'.$modulename.'.interface.php';		
		} else {
			return $oh['path'].'/modules/'.$modulename.'/'.$modulename.'.interface.php';	
		}
	}
	
	function oh_framework_is_installed() {
		global $oh;
		return is_dir($oh['path']."/includes");
	}
	
			
	function oh_var_name($var) {
	    foreach($GLOBALS as $var_name => $value) {
	        if ($value === $var) {
	            return $var_name;
	        }
	    }	
	    return false;
	}
	
	function oh_module_exists($module) {
		return
		file_exists(
			oh_module_interface_file($module)
		);
	}
	
	function oh_module_require($interfaces) {
		foreach($interfaces as $interface) {
			if (file_exists($interface)) {
				require_once($interface);
				return true;
			}
		}
		return false;
	}
	
	function oh_module_parse($module) {
		global $oh;
		
		$module 	= explode(".",$module);
		$module[0] 	= strtolower($module[0]);

		$output_module['name'] 			= $module[0];
		$output_module['token'] 		= array_slice($module, 1);
		$output_module['function'] 		= "oh_module_".$module[0];
		$output_module['interface'] 	= array();
		$output_module['interface'][] 	= oh_module_interface_file($module[0]);

		$packs = oh_module_packs();
		foreach($packs as $pack) {
			$output_module['interface'][] = oh_module_interface_file($module[0],$pack);
		}
		
		return $output_module;
	}

	function oh_properties($s) {
		$o = array();
		$s = preg_replace("/[ \t\r\n]+/","",$s);
		$s = explode(",",$s);		
		foreach($s as $i) {
			$i = explode(":",$i);
			$o[$i[0]] = $i[1];
		}
		return $o;
	}
	
	function &oh_this() {
		global $oh;

		$d = debug_backtrace();			
		$file00	= basename($d[0]["file"]);		
		$module = false;
		
		if (!$module) {
			$module = oh_get_module_by_filename($file00);
		}
		if (!$module) {
			$module = oh_last_module_in_stack();
		}
		
		global ${"oh_object_".$module};
		return ${"oh_object_".$module};
	}

	function oh_get_module_by_filename($filename) {
		$filename = explode(".",$filename);
		if (($filename[1]=="interface")&&(($filename[1]=="interface"))) {
			return $filename[0];
		}
		return NULL;
	}
	
	function oh_underscore($name) {
		return str_replace("-","_",$name);
	}
	
	function oh_this_name() {
	
	}

	function oh_last_module_in_stack() {
		global $oh;
		return $oh['module'][count($oh['module'])-1];
	
	}

	function oh_math_integer_divide($x, $y) {
		if ($x == 0) return 0;
		if ($y == 0) return FALSE;
		return ($x - ($x % $y)) / $y;
	}

	
	class oh_interface {
		public $source;
		function identity() {			
		}
	}
?>
